import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import naive from 'naive-ui'
import { createDiscreteApi } from 'naive-ui'
import { router } from './common/router'
import { createPinia } from 'pinia'
import axios from 'axios'
import {AdminStore} from "./store/AdminStore"

const baseUrl = "http://localhost:8080"
axios.defaults.baseURL = baseUrl

const { message, notification, dialog } = createDiscreteApi([
  'message',
  'dialog',
  'notification',
])

const app = createApp(App)
app.provide('axios', axios)
app.provide('message', message)
app.provide('notification', notification)
app.provide('dialog', dialog)
app.provide('baseUrl', baseUrl)
app.use(naive)
app.use(createPinia())
app.use(router)
app.mount('#app')

const adminStore = AdminStore()
// 请求拦截器为请求统一添加token，注意要放在app.use(createPinia())之后
axios.interceptors.request.use((config) => {
  config.headers.token = adminStore.token
  return config
})

